# coding=utf-8
import base64
import binascii
from gmssl import sm2, func
from base64 import b64encode,b64decode
private_key = '5cc9446b51644f80c646e1c08f4c0db09c123f0018cf8f0d9d25246ca10aa4ca'
public_key = 'd2fc36919cba823235df6c47138b1ad3358146172c4d1c8c85d13eea3eff52fd3f3371c4a5133c0e122d22d56205761050e480be1a7792303acfaca30e2e0925'
sm2_crypt = sm2.CryptSM2(
    public_key=public_key, private_key=private_key)
data = b"eeeeeeeeeee"
enc_data = sm2_crypt.encrypt(data)
print(b64encode(enc_data).decode('utf-8'))
dec_data =sm2_crypt.decrypt(enc_data)
print(dec_data.decode('utf-8'))
# assert dec_data == data

data = b"qqqq" # bytes类型
random_hex_str = func.random_hex(sm2_crypt.para_len)
sign = sm2_crypt.sign(data, random_hex_str) #  16进制
assert sm2_crypt.verify(sign, data) #  16进制